var tgd = tgd || {};
tgd.Math = tgd.Math || {};
tgd.Math.Views = tgd.Math.Views || {};

tgd.Math.Views.CanvasMandelbrot = function (mandelbrot, canvas) {
	this._mandelbrot = mandelbrot;
	this._context = canvas.getContext('2d');

	//i thought this would have worked
	//canvas.width = canvas.height = mandelbrot.getDimension();
	//but i'll try this to make it happy?
	this._context.canvas.width = mandelbrot.getDimension();
	this._context.canvas.height = mandelbrot.getDimension();

	for (var i = 0; i < this._mandelbrot.getDimension(); ++i) {
		for (var j = 0; j < this._mandelbrot.getDimension(); ++j) {
			var val = this._mandelbrot.getValue(i, j);
			//tgd:  from reading html5 spec, 4.8.11.1.7, i don't think strokeStyle is needed.
			//this._canvas.strokeStyle = (val == this._mandelbrot.getMaxIteration() ? "#000000" : "#" + ("000000" + ((val + 100000) * 10).toString(16)).match(".{6}$"));
			this._context.fillStyle = (val == this._mandelbrot.getMaxIteration() ? "#000000" : "#" + ("000000" + ((val + 100000) * 10).toString(16)).match(".{6}$"));
			this._context.fillRect(j, i, 1, 1);
		}
	}
	
}